#pragma once

#include "99_Initialization.h"
#include "Logging.h"
#include "MeshReader.h"
#include <fstream>
#include <string>

class BC_gridgen_mod;
class Initialization;
class GridgenReader : public MeshReader
{
public:
  /* GridgenReader(BC_gridgen_mod& mod)
    : _bc_gridgen_mod(mod){}*/
  GridgenReader(Initialization& init)
    : _intialization(init)
    , _base_data_mod(init._base_data_mod)
    , _total_contr_param(init._total_contr_param)
    , _conv_mod(init._conv_mod)
    , _bc_gridgen_mod(init._bc_gridgen_mod)
  {
  }
  ~GridgenReader() = default;

  void SetGridFileName(const std::string& grid_file, const std::string& bc_file)
  {
    this->_grid_file = grid_file;
    this->_bc_file = bc_file;
  }


  void Read() override;
  //<<<<<<< HEAD
  void Read_BC_grdgen();
  void Read_BC_grdgen_Sub(std::ifstream& ifile, int izone);
  void Buil_ZoneBC_grdgen(int izone, Type_def::FieldonGrids_t& _field_grids);
  void Read_Grid_grdgen();
  void Read_Grid_grdgen_Sub(std::ifstream& ifile,
                            int nformat,
                            int ncoord,
                            sunflow::Vector<int>& m,
                            sunflow::Array<real, 4>& xyz);

  int sign_sunflow(int a, int b);
  int samesign(int n1, int n2);
  void Build_ZoneMatchBC_trans(sunflow::Vector<int>& m1,
                               sunflow::Vector<int>& m2,
                               Type_def::Connectivity1to1_t& BC1to1);


  template<typename T>
  T BinaryRead(std::ifstream& ifile)
  {
    T v;
    ifile.read((char*)&v, sizeof(v));
    return v;
  }


  void TestBinary();

private:
  std::string _grid_file, _bc_file;
  Initialization& _intialization;
  BaseData_mod& _base_data_mod;
  TotalCorPar_mod& _total_contr_param;
  conv_mod& _conv_mod;
  BC_gridgen_mod& _bc_gridgen_mod;
};
